package lc;

import java.util.LinkedHashMap;

public class LongestConsecutiveSequence {
    public int longestConsecutive(int[] num) {
    	LinkedHashMap<Integer, Boolean> map = new LinkedHashMap<Integer, Boolean>();
    	for (int i : num) {
    		map.put(i, false);
    	}
    	
    	int maxlen = 0;
    	
    	for (int i : num) {
    		if (map.get(i)) {
    			continue;
    		}
    		
    		map.put(i, true);    		
    		int len = 1;
    		
    		for (int j=i+1; map.containsKey(j); j++) {
    			map.put(j, true);
    			len++;
    		}
    		
    		for (int j=i-1; map.containsKey(j); j--) {
    			map.put(j, true);
    			len++;
    		}
    		
    		maxlen = Math.max(maxlen, len);    		
    	}
    	
    	return maxlen;
    }

    public static void main(String ...strings) {
//    	int [] num = {100, 4, 200, 1, 3, 2};
    	int [] num = {0};
    	LongestConsecutiveSequence sol = new LongestConsecutiveSequence();
    	int longestConsecutive = sol.longestConsecutive(num);
    	System.out.println(longestConsecutive);
    }
}
